package com.eascs.admin.o2o.loan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.admin.o2o.loan.dao.LoanapplyOpLogDao;
import com.eascs.admin.o2o.loan.entity.O2oLoanScToptencInfo;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.common.util.StringUtil;

@Service
public class O2oLoanScTopTenCService implements IO2oLoanGsScService<O2oLoanScToptencInfo>{

	@Autowired
	LoanapplyOpLogDao dao;
	
	public int insertEntity(O2oLoanScToptencInfo t) {
		dao.insert(t);
		return 1;
	}

	public int updateEntity(O2oLoanScToptencInfo t) {
		dao.updateById(t);
		return 0;
	}

	public O2oLoanScToptencInfo getEntityById(String id) {
		String sql = "select * from o2o_loan_sc_toptenc_info where id=? ";
		return dao.findEntity(sql, O2oLoanScToptencInfo.class, id);
	}
	
	public O2oLoanScToptencInfo getEntityByLoan(String loanpplyNo) {
		String sql = "select * from o2o_loan_sc_toptenc_info where loanapply_no=? ";
		return dao.findEntity(sql, O2oLoanScToptencInfo.class, loanpplyNo);
	}
	
	public int delete(String id){
		return dao.deleteById(O2oLoanScToptencInfo.class, id);
	}

	public List<O2oLoanScToptencInfo> queryEntitys(O2oLoanScToptencInfo t) {
		return null;
	}
	
	public int queryEntitysSize(String loanapplyNo ) {
		String sql =  "select count(*) from o2o_loan_sc_toptenc_info where loanapply_no=? ";
		return dao.findInteger(sql, loanapplyNo);
	}

	public PageResult<Object[]> queryPage(O2oLoanScToptencInfo t, int pageSize, int pageIndex) {
		SqlPageQuery<Object[]> pageQuery = new SqlPageQuery<>(Object[].class, pageSize, pageIndex);
		String querySql = "select id,cus_name,settlement_date,supply_quantity,loanapply_no from o2o_loan_sc_toptenc_info where 1=1 ";
		if(StringUtil.isNotBlank(t.getLoanapplyNo())){
			querySql = querySql + " and loanapply_no=?";
			pageQuery.addParam(t.getLoanapplyNo());
		}
		pageQuery.setQuerySql(querySql);
		return dao.findDataWithPage(pageQuery);
	}

}
